package com.aube.guide;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;

/**
 * Created by mertsimsek on 25/01/16.
 */
public class Circle {

    private Target target;

    private int radius;

    private Point circlePoint;

    private int padding;

    private Paint paint;

    public Circle(Target target, int padding, int color) {
        this.target = target;
        this.padding = padding;
        circlePoint = getFocusPoint();
        calculateRadius(padding);

        this.paint = new Paint();
        this.paint.setAntiAlias(true); //消除锯齿
        this.paint.setStyle(Paint.Style.STROKE); //绘制空心圆
        this.paint.setColor(color);
    }

    public void draw(Canvas canvas, Paint eraser, int padding){
        calculateRadius(padding);
        circlePoint = getFocusPoint();
        canvas.drawCircle(circlePoint.x, circlePoint.y, radius-10, eraser);

        drawCircle(canvas, radius-10);
    }

    public void drawCircle(Canvas canvas, int radius) {
        int ringWidth = 5; //设置圆环宽度

        //绘制圆环
        this.paint.setStrokeWidth(ringWidth);
        canvas.drawCircle(circlePoint.x, circlePoint.y, radius+1+ringWidth/2, this.paint);
    }

    private Point getFocusPoint(){
        return target.getPoint();
    }

    public void reCalculateAll(){
        calculateRadius(padding);
        circlePoint = getFocusPoint();
    }

    private void calculateRadius(int padding){
        int side = Math.max(target.getRect().width() / 2, target.getRect().height() / 2);
        radius = side + padding;
    }

    public int getRadius(){
        return radius;
    }

    public Point getPoint(){
        return circlePoint;
    }

}
